package com.hjt.zhibo.collect.impl;

import java.util.ArrayList;
import java.util.List;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.hjt.zhibo.collect.ITVPlatform;
import com.hjt.zhibo.model.PlatFormCatalog;
import com.hjt.zhibo.model.TVCatalog;
import com.hjt.zhibo.model.TVRoom;
import com.hjt.zhibo.tools.HttpContent;

public class PandaTV implements ITVPlatform{
	
	private String baseUrl = "http://www.panda.tv";
	private String catalogUrl = "http://www.panda.tv/cate/";
	private String platform = "熊猫";
	
	
	@Override
	public List<TVCatalog> getTVCatalog() {
		List<TVCatalog> list = new ArrayList<TVCatalog>();
		
		Document doc = Jsoup.parse(HttpContent.getUrlContent(catalogUrl));
		Elements links = doc.select("ul.sidebar-list.sidebar-list-2.clearfix li");
		for (Element link : links) {
			Element linkA = link.select("a").first();
			String url = linkA.attr("href");
			if(url.startsWith("http:")){
				continue;
				//list.add(new TVCatalog(link.attr("title"), url, link.attr("data-ename")));
			} else{
				list.add(new TVCatalog(link.attr("title"), baseUrl+url, link.attr("data-ename")));
			}
			
		}
		return list;
	}

	@Override
	public List<TVRoom> getTVRoom(TVCatalog tVCatalog) {
		List<TVRoom> list = new ArrayList<TVRoom>();
		
		Document doc = Jsoup.parse(HttpContent.getUrlContent(tVCatalog.getUrl()));
		Elements links = doc.select("ul#sortdetail-container li");
		for (Element link : links) {
			Element linkA = link.select("a").first();
			Element img = linkA.select("img").first();
			String imgSrc = img.attr("src");
			String title = linkA.select("div.video-title").first().attr("title");
			String auth = linkA.select("div.video-info").first().select("span.video-nickname").html();
			String count = linkA.select("div.video-info").first().select("span.video-number").html();
			String roomUrl = baseUrl + linkA.attr("href");

			list.add(new TVRoom(imgSrc, title, auth, count, roomUrl, tVCatalog.getCnName(), platform));
		}
		return list;
	}

	@Override
	public List<TVRoom> getTVRoom(PlatFormCatalog platFormCatalog) {
		// TODO Auto-generated method stub
		return null;
	}

	
}
